<template>
    <div>
        <el-form :model="ruleForm" :rules="rules" ref="form" label-width="120px" class="demo-ruleForm">
            <el-form-item label="客户名称" prop="cnName">
                <el-input v-model="ruleForm.cnName" disabled ></el-input>
            </el-form-item>
            <el-form-item label="商机描述" prop="opptDesc">
                <el-input  v-model="ruleForm.opptDesc"></el-input>
            </el-form-item>
            <el-form-item label="商机类型" prop="opptType">
                <el-select v-model="ruleForm.opptType" placeholder="请选择">
                    <el-option
                            v-for="item in opptList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="预计金额" prop="money">
                <el-input-number :controls="false" style="width: 50%" v-model="ruleForm.money"></el-input-number>
            </el-form-item>
            <el-form-item label="中标概率" prop="probability">
                <el-select v-model="ruleForm.probability" placeholder="请选择">
                    <el-option
                            v-for="item in probabilityList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="状态" prop="stat">
                <el-select v-model="ruleForm.stat" placeholder="请选择">
                    <el-option
                            v-for="item in statList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="联系人手机号" prop="phone">
               <el-input v-model="ruleForm.phone" style="width: 50%"></el-input>
            </el-form-item>

        </el-form>
    </div>
</template>

<script>
    import {updateCust}from '@/api/projectApi'
    export default {
        props: {
            params: {
                type: Object,
                default () {
                    return {}
                }
            }
        },
        data() {
            return {
                ruleForm: {
                    cnName: '',
                    opptDesc: '',
                    opptType:'',
                    money: '',
                    probability: '',
                    stat:'',
                    phone:''
                },
                probabilityList:[
                    {
                        value: '0',
                        label: '<30%'
                    },
                    {
                        value: '1',
                        label: '=50%'
                    },
                    {
                        value: '2',
                        label: '>50%'
                    },
                ],
                opptList:[
                    {
                        value: '0',
                        label: '招投标'
                    },
                    {
                        value: '1',
                        label: '单一来源'
                    },
                ],
                statList:[
                    {
                        value: '0',
                        label: '合作'
                    },
                    {
                        value: '1',
                        label: '终止'
                    },
                ],
                rules: {
                    cnName: [
                        { required: true, message: '客户名称不可为空', trigger: 'blur' },
                    ],
                    opptDesc: [
                        { required: true, message: '商机描述不可为空', trigger: 'blur' },
                    ],
                    opptType: [
                        { required: true, message: '商机类型不可为空', trigger: 'change' },
                    ],
                }
            };
        },
        methods: {
            //提交
            submit() {
                return new Promise((resolve, reject) => {
                    this.$refs['form'].validate((valid) => {
                        if(valid){
                            updateCust(this.ruleForm).then(res => {
                                resolve(res.data)
                            }).catch(e => {
                                console.log(e,555)
                                reject(e)
                                this.$message.error({
                                    message: '抱歉，操作遇到异常，请重试或联系管理员处理'
                                })
                            })
                        }else {
                            this.$message.error('业务校验未通过')
                            reject(new Error('业务校验失败'))
                        }
                    })
                })

            }
        },
        mounted() {
            this.ruleForm={...this.ruleForm,...this.params}
        }
    }
</script>

<style scoped>

</style>
